﻿using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace LocalOverride.Fiddler.Store
{
    public class SpecialCaseMappingList : ICollection<SpecialCaseMapping>
    {
        readonly IList<SpecialCaseMapping> specialCaseMappingList = new List<SpecialCaseMapping>();
        public IEnumerator<SpecialCaseMapping> GetEnumerator()
        {
            return specialCaseMappingList.GetEnumerator();
        }

        public bool Equals(SpecialCaseMappingList other)
        {
            var thisHasAllOtherItems = this.All(other.Contains);
            var otherHasAllTheseItems = other.All(Contains);

            return thisHasAllOtherItems && otherHasAllTheseItems;
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof (SpecialCaseMappingList)) return false;
            return Equals((SpecialCaseMappingList) obj);
        }

        public override int GetHashCode()
        {
            return (specialCaseMappingList != null ? specialCaseMappingList.GetHashCode() : 0);
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        public void Add(SpecialCaseMapping item)
        {
            specialCaseMappingList.Add(item);
        }

        public void Clear()
        {
            specialCaseMappingList.Clear();
        }

        public bool Contains(SpecialCaseMapping item)
        {
            return specialCaseMappingList.Contains(item);
        }

        public void CopyTo(SpecialCaseMapping[] array, int arrayIndex)
        {
            specialCaseMappingList.CopyTo(array,arrayIndex);
        }

        public bool Remove(SpecialCaseMapping item)
        {
            return specialCaseMappingList.Remove(item);
        }

        public int Count
        {
            get { return specialCaseMappingList.Count; }
        }

        public bool IsReadOnly
        {
            get { return specialCaseMappingList.IsReadOnly; }
        }
    }
}